local skill = fk.CreateSkill{
  name = "tea__suizuo",
}
---@type TrigSkelSpec<TrigFunc>
local suizuo = {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skill.name) then return end
    if event == fk.RoundStart then
      return true
    else
      return target.chained
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local targets = table.filter(room:getOtherPlayers(player), function(p)
        return not p.chained
      end)
      local num = 1
      if player.chained and #targets > 1 then
        num = 2
      end
      local tos = room:askToChoosePlayers(player, {
        targets = targets,
        min_num = num,
        max_num = num,
        skill_name = skill.name,
        prompt = "#tea__suizuo-choose:::" .. tostring(num),
      })
      if #tos > 0 then
        event:setCostData(self, tos)
        return true
      end
    else
      return room:askToSkillInvoke(player, {skill_name = skill.name, prompt = "#tea__suizuo-invoke:" .. target.id}) and player:getMark("tea__zuizuo_count-round") < player.hp
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      room:notifySkillInvoked(player, skill.name, "drawcard")
      player:broadcastSkillInvoke(skill.name, table.random{1, 2})
      local targets = event:getCostData(self)
      room:sortByAction(targets)
      if not player.chained then
        player:setChainState(true)
      end
      for _, p in ipairs(targets) do
        p:setChainState(true)
      end
      for _, p in ipairs(room.alive_players) do
        if p.chained then
          p:drawCards(1, skill.name)
        end
      end
    else
      room:notifySkillInvoked(player, skill.name, "support")
      player:broadcastSkillInvoke(skill.name, 3)
      room:addPlayerMark(player, "tea__zuizuo_count-round", 1)
      player:drawCards(1,skill.name)
      if not player.dead and not player:isNude() and player ~= target then
        local cid = room:askToCards(player, {
          min_num = 1,
          max_num = 1,
          skill_name = skill.name,
          cancelable = false,
          include_equip = true,
          prompt = "#tea__suizuo-give:" .. target.id,
        })
        if #cid == 1 then
          room:obtainCard(target, cid, false, fk.ReasonGive)
        end
      end
    end
  end,
}
skill:addEffect(fk.RoundStart, suizuo)
skill:addEffect(fk.TurnStart, suizuo)
return skill